<?php
/*
 * @Author: lyj
 * @Date: 2024-08-07 13:30:00
 * @LastEditors: lyj
 * @Description: 私域直播-订金列表
 */

 namespace app\apiadmin\controller\live;

use app\common\controller\BaseController;
use app\apiadmin\service\deposit\DepositService;
use app\common\utils\Res;
use think\facade\Db;

class Deposit extends BaseController
{
    //定金列表
    public function list(){
        $param = $this->request->post();

        $deposit_service = DepositService::getInstance();

        $result = $deposit_service->pageList($param);

        return Res::ok($result);
    }
    //添加/编辑
    public function edit(){
        $uid = $this->request->uid;

        $param = $this->request->post();

        $deposit_service = DepositService::getInstance();

        $deposit_service->setUid($uid);

        $result = $deposit_service->edit($param);

        if(!$result['res']){
            return Res::error($result['msg']);
        }
        return Res::ok();
    }
    //退款
    public function tuikuan(){
        $param = $this->request->post();
        $deposit_service = DepositService::getInstance();
        $result = $deposit_service->tuikuan($param);
        if(!$result['res']){
            return Res::error($result['msg']);
        }
        return Res::ok();
    }
    public function info(){
        $param = $this->request->post();
        $deposit_service = DepositService::getInstance();
        $result = $deposit_service->info($param);
        return Res::ok($result);
    }

    public function siyuCourseList(){
        $list = Db::name('siyu_course')
            ->where(['del'=>0])
            ->field('id,name,fee')
            ->select()
            ->each(function($item){
                $item['fee_name']=bcdiv($item['fee'],100,2);
                return $item;
            })
            ->toArray();
        if(!$list){
            return Res::ok([]);
        }
        return Res::ok($list);
    }
}